import HTMLParser
import urllib
import re
import string


urlString = "http://www.six.sk/aktual_peering.php?lang=en"
urlText = []
pathOut = "ixp_members.txt"


class Parse55 (HTMLParser.HTMLParser):
    
    check = False
    
    def handle_starttag (self, tag, attrs):
        if tag == "font":
            for name, value in attrs:
                if name == "color" and value == "#000000":
                    self.check = True
    
    def handle_data (self, data):
        if self.check == True and re.match("^ AS\d+$",data):
            data = string.lstrip(data," AS")
            if data not in urlText:
                urlText.append(data)
        self.check = False


lparser = Parse55()
lparser.feed(urllib.urlopen(urlString).read())
fileOut = open(pathOut, "a")
for item in urlText:
    #print item # debug
    print >> fileOut, "55 %s" % item
fileOut.close()